package com.icez.base_util_library.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView

/**
 * RecyclerView 适配器基类
 * @author Icez
 */
abstract class CalendarViewAdapter<T,VB:ViewDataBinding>(val mLayoutResId:Int, val mData:ArrayList<T>?):
    RecyclerView.Adapter<CalendarViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CalendarViewHolder {
        val binding = DataBindingUtil.inflate<VB>(LayoutInflater.from(parent.context),mLayoutResId,parent,false)
        return CalendarViewHolder(binding)
    }

    override fun onBindViewHolder(holder: CalendarViewHolder, position: Int) {
        onBusinessOperation(holder.mBinding.root.context,holder.mBinding as VB,position,mData?.get(position))
    }

    override fun getItemCount(): Int {
        return mData?.size?:0
    }

    /**
     * 业务操作
     *
     * @param context 上下文
     * @param binding databinding
     * @param position 索引
     * @param item 数据
     */
    abstract fun onBusinessOperation(context: Context, binding:VB, position: Int, item:T?)
}